import json
import kkl_config
import requests


class LoginApi:
    def __init__(self):
        self.url = kkl_config.URL
        self.xhxurl = kkl_config.URL_xhx_login

    def loginMobile(self):
        login_data = {
            "secret_state": "F6D375DF5657B1D755C7FF709046D891",
            "service_name": "kusercen.LoginFacade.loginMobile",
            "strategy": "dubbo",
            "param": {
                "loginInfo": {
                    "password": "6b3c802297ddc39034ced2771492c7f485376829d3e4d09a02ba79788951c67bf64",
                    "mobileNo": "13221085986",
                    "deviceId": "D414C492-80A2-4615-A640-B1E180036031",
                    "clientType": "ios",
                    "userAgent": "KKLOnLine/5.28.0 (iPhone; iOS 13.6; Scale/3.00; appVersion 5.28.0; XHX)",
                    "loginIp": "172.17.2.49"
                }
            },
            "token": "",
            "timestamp": "1668676167038",
            "client_id": "6"
        }
        response = requests.post(self.url,json=login_data)
        response_data = response.json()
        # print(json.dumps(response_data,ensure_ascii=False, indent=2))
        print("-"*50)
        # kkl_config.prints(response)
        kkl_config.Token.token = response_data["data"]["resultObject"]["token"]
        print("toekn:" + kkl_config.Token.token)



    def xhxLogin(self):
        xhxlogin_data ={
            "username":"13221080002",
            "password":"123456"
        }
        responses = requests.post(self.xhxurl,data=xhxlogin_data)
        res_data = responses.json()
        kkl_config.Token.xhxtoken = res_data["data"]
        print("xhxtoken:" + kkl_config.Token.xhxtoken)


if __name__ == "__main__":
    login = LoginApi().loginMobile()
    xhxlogin = LoginApi().xhxLogin()